package com.chx.mapper;

import com.chx.entity.PurchaseOrderDetails;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author cp-月入过万
 * @Date 2025/5/30
 */
@Mapper
public interface PurchaseOrderDetailMapper {
    @Insert("insert into purchase_order_details (order_id, product_id, purchase_price, quantity, subtotal) values (#{orderId}, #{productId}, #{purchasePrice}, #{quantity}, #{subtotal})")
    void insert(PurchaseOrderDetails purchaseOrderDetails);

    @Delete("delete from purchase_order_details where order_id = #{orderId}")
    void deleteByOrderId(Long orderId);

    @Select("select * from purchase_order_details where order_id = #{id}")
    List<PurchaseOrderDetails> getByOrderId(Long id);

    @Select("select count(*) as total from purchase_order_details where product_id=#{id}")
    int getByProductId(Long id);
}
